﻿@model qltscd.Models.ScreenClient.ThanhLyScreenClient
@{
    ViewBag.Title = "ThanhLy";
    Layout = "~/Views/Shared/Modules/_LayoutTacVuNhapLieu.cshtml";
}

<h2>Thanh lý thiết bị</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    function openWindow() {
        var window = getWindow();
        window.center();
        window.open();
    }
    function closeWindow() {
        var window = getWindow();
        window.close();
    }
    function getWindow() {
        return $('#wdSearch').data('tWindow');
    }
    function onOpenWindow() {
        document.getElementById('mahopdong').value = '';
        document.getElementById('mahopdong').focus();
    }
    function submitForm() {
        document.location = "/QuanLyThietBi/DanhMucThietBi/ThanhLy/?MaHopDong=" + document.getElementById('mahopdong').value;
    }

    function submitTaoThietBiTheoHopDong(kieu) {
        document.getElementById("kieuLuu").value = kieu;
        document.forms["TaoThietBiTheoHopDong"].submit();
    }

    function onlyNumbers(e) {
        var keynum;
        var keychar;
        var numcheck;

        if (window.event) // IE8 and earlier
        {
            keynum = e.keyCode;
        }
        else if (e.which) // IE9/Firefox/Chrome/Opera/Safari
        {
            keynum = e.which;
        }
        keychar = String.fromCharCode(keynum);
        numcheck = new RegExp("[0-9/]");
        return numcheck.test(keychar);

        function GetTenNhaCungCap() {
            var combobox = $("#IdentityThietBi").data('tComboBox');
            var url = '/QuanLyThietBi/DanhMucThietBi/GetTenNhaCungCap?thietbi=' + combobox.value();
            $.post(url, function (data) {
                $('#TenThietBi').val(data.TenThietBi);
            });
        }
    }
</script>
@(
 Html.Telerik().Window()
        .Name("wdSearch")
        .Height(100)
        .Title("Tìm Thiết Bị")
        .Width(400)
        .Content(@<text>
@using (Html.BeginForm("ThanhLy", "DanhMucThietBi", FormMethod.Post, new { @id = "TimHopDong" })) {
    <text>
    <div style="width: 100%; height: auto; text-align: left;">
        Mã hợp đồng:
        <input type="text" style="width: 70%" name="mahopdong" id="mahopdong" />
    </div>
    <div style="width: 100%; height: auto; text-align: center; padding-top: 15px;">
        <input type="button" value="Tìm Thiết bị" class="button" onclick="submitForm()" />
        <input type="button" value="Đóng" onclick="closeWindow();" class="button" />
    </div>
    </text>
}
</text>)
        .Modal(true)
        .Buttons(button => {
            button.Close();
        })
        .Visible(false)
        .Draggable(true)
        .Resizable()
        .ClientEvents(e => e.OnOpen("onOpenWindow"))
)
@using (Html.BeginForm("ThanhLy", "DanhMucThietBi", FormMethod.Post, new { @id = "TaoThietBiTheoHopDong" })) {
    @Html.ValidationSummary(true)
    @Html.HiddenFor(o => o.IdentityThanhLy)
    <input type="hidden" name="kieuLuu" id="kieuLuu" value="0" />
    <fieldset>
        <legend>Thông tin chung</legend>
        <table border="0" width="100%" cellpadding="10px" cellspacing="10px">
            <tr>
                <td style="margin-left: 10px;" class="label_col">
                    Mã thanh lý
                </td>
                <td>
                      @Html.TextBoxFor(model => model.MaThanhLy, new { @style = "width:97%;" })
                @Html.ValidationMessageFor(model => model.MaThanhLy)
                @ViewData[qltscd.Contansts.SessionConstants.ERROR_MESSAGE]
                </td>
               <td style="margin-left: 10px;" class="label_col">
                    Người ký
                </td>
                <td>
                     @Html.TextBoxFor(model => model.NguoiKy, new { @style = "width:97%;" })
                @Html.ValidationMessageFor(model => model.NguoiKy)
                @ViewData[qltscd.Contansts.SessionConstants.ERROR_MESSAGE]
                </td>
            </tr>
            <tr>
                <td style="margin-left: 10px;" class="label_col">
                   Ngày ký
                </td>
                <td>
   @(Html.Telerik().DatePicker()
                    .Name("NgayKy")
                    .Format("dd/MM/yyyy")
                    .HtmlAttributes(new { @style = "width:97%; " })
                    .InputHtmlAttributes(new { @style = "width:100%; ", @onblur = "DatePickerOnBlur()" })
                )
                    @Html.ValidationMessageFor(model => model.NgayKy)
                </td>
                <td style="margin-left: 10px;" class="label_col">
                    Lý do giảm
                </td>
                <td>
                   @(Html.Telerik().ComboBox()
                    .Name("IdentityLyDoGiam")
                    .HtmlAttributes(new { @style = "width:97%;" })
                    .InputHtmlAttributes(new { @style = "width:100%; " })
                    .BindTo((SelectList)ViewBag.IdentityLyDoGiam)
                )
                    @Html.ValidationMessageFor(model => model.IdentityLyDoGiam)
                </td>
               
            </tr>
          
            <tr>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>Thông tin thiết bị</legend>
        @{
               Html.Telerik().Grid(Model.DSThietBiThanhLy)
               .Name("grdDSTBTL")
               .DataKeys(keys =>
               {
                   keys.Add(c => c.IdentityThietBi);
               })
               .Resizable(r => r.Columns(true))
               .Reorderable(r => r.Columns(true))
               .Sortable()
               .Scrollable(s => s.Enabled(true).Height(200))
               .Pageable(paging => paging.Enabled(true).Style(GridPagerStyles.NextPreviousAndInput).PageSize(10))
               .Editable(e => e.Mode(GridEditMode.InCell))
               .NoRecordsTemplate("Không có thiết bị")
               .ToolBar(t =>
               {
                   t.Insert()
                      .Text("Thêm thiết bị")
                      .ButtonType(GridButtonType.ImageAndText);
                   t.SubmitChanges().SaveText("Lưu").CancelText("Hủy").ButtonType(GridButtonType.ImageAndText);
               })
               .DataBinding(databinding =>
               {
                   databinding.Server()
                       .Select("ThanhLy", "DanhMucThietBi");
                   databinding.Ajax()
                       .Select("_ThanhLy", "DanhMucThietBi")
                       .Update("_UpdateThietBi", "DanhMucThietBi");
               })
               
               .Columns(column =>
               {
                   column.Bound(i => i.IdentityThietBi).Visible(false);
                   column.Bound(i => i.MaThietBi).Title("Mã thiết bị").Width(100);
                   column.Bound(o => o.SerialThietBi).Title("Serial thiết bị").EditorTemplateName("SerialThietBi").Width(100);
                   column.Bound(o => o.TenThietBi).Title("Tên thiết bị").Width(150);
                   column.Bound(o => o.TheThietBi).Title("Thẻ thiết bị").Width(10);
                   
                   column.Command(cmd =>
                   {
                       cmd.Delete()
                           .ButtonType(GridButtonType.Image)
                           .Text("Xóa");
                   }).Width(30);
               })
               .Render();
                       
        }
    </fieldset>
    <div class="divButton">
    <input type="submit" value="Lưu" class="button" />&nbsp;
    <input type="button" value="Tìm Thiết bị" class="button" onclick="openWindow();" />&nbsp;
    <input type="reset" value="Nhập lại" class="button" />&nbsp;
    @Html.ActionLink("Thoát", "Index", null, new { @class = "button" })
</div>
}

